Random Functions
Default function found on the web
GLSL doesn't give (anymore?) a random function to generate random numbers. Which means that if necessary, a function need to be coded to generate random number.
The topic of generating random number is wide and complex, what is important to remember is that real randomness is hard to obtain on a computer so we sometime hear about Pseudo-random (). Concept
Main idea to generate random number is to create a function that will use large numbers on operations so that the outcome of this function looks unpredictable and any minimal change on the input will change a lot the output.
There is multiple ways to generate a random function, which will have certain properties in terms of efficiency, distribution etc.
https://scrapbox.io/files/65c086e5b51fc90024fbb4e0.png
This paper has mesured differnt PRNG implementation based on their time of execution and "proper randomness" mesured with the BigCrush Tests methodology. A subset of them, representing the Pareto frontier of this test, are the ones that are optimal in time based on their BigCrush result code:random.glsl
uint seed = 12512;
uint hashi( uint x){// hashes
x ^= x >> 16;x *= 0x7feb352dU;x ^= x >> 15;x *= 0x846ca68bU;x ^= x >> 16; return x;
}
#define hash_f() ( float( seed = hashi(seed) ) / float(-1u ) ) #define hash_v2() vec2(hash_f(),hash_f()) #define hash_v3() vec3(hash_f(),hash_f(),hash_f()) Random unit vector
Other